package StringSecond.SwordOffer;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class LengthOfLongestSubstring {
    public static int lengthOfLongestSubstring(String s) {
        Set<Character> set = new HashSet<>();
        int fast = -1;
        int ans = 0;
        for (int i = 0; i < s.length(); i++) {
            if (i != 0) {
                set.remove(i);
            }
            while (fast + 1 < s.length() && !set.contains(s.charAt(fast + 1))) {
                set.add(s.charAt(fast + 1));
                fast++;
            }
            ans = Math.max(ans, fast - i + 1);
        }
        return ans;
    }

    public static void main(String[] args) {
        int abcabcbb = lengthOfLongestSubstring("abcdabcbb");
        System.out.println(abcabcbb);
    }
}
